<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="mycrmprkaushik.Customer" %>
<%@ page import="mycrmprkaushik.PMF" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="java.util.List" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>


<html>
 <head>
  <title>Simple CRM</title>
  	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
	<style media="all" type="text/css">@import "./css/all.css";</style>
  </head>
<body>
		<div id="main">
		<div id="header">
			<a href="/home/" class="logo"><img src="../img/simpleCRM.jpg"
				width="230" height="" alt="80" />
			</a>
			<ul id="top-navigation">
				<li><span><span><a href="/customers.jsp">Homepage</a></span>
				</span>
				</li>
			</ul>
		</div>
		
		<div id="middle">
			<div id="left-column">
			<h3>Quick Launch</h3>
			<ul class="nav">
				<li><a href="#">Add New Customer</a></li>
				<li><a href="#">Add Customer Activity</a></li>
				<li><a href="#">Add Users</a></li>
			</ul>
			</div>
		
			<div id="center-column">
			<form action="/addcust" method="post">
	   		<table border="0">
			<tr><td><align="right"><div class="formtext">Name:</div></td>
			<td><input type =text name="name" size=25></td>			
			<td><align="right">Company:</td>
			<td><input type =text name="company" size=25></td></tr>
			<tr><td><align="right">Phone:</td><td><input type =text name="phone" size=25></td>		
			<td><align="right">Address:</td><td><input type =text name="address" size=25>
			<input type="submit" value="Create Customer" /></td>			
			</tr>		   
     		</table>
    		</form>

				My Customers 
				<%
				PersistenceManager pm = PMF.get().getPersistenceManager();
				String query = "select from " + Customer.class.getName();
				List<Customer> customers = (List<Customer>) pm.newQuery(query).execute();
				%>				
				<div class="table"> 
				<table class="listing" cellpadding="0" cellspacing="0">
					<tr>
						<th class="first" width="10"><center>Name</center></th>
						<th><center>Address</center></th>
						<th><center>Company</center></th>
						<th><center>Telephone</center></th>
						<th>Delete</th>
						<th>Edit</th>
					</tr>
				<%
				if (customers.isEmpty()) {
				%>
					<p>No Customers</p>
				<%
					} else {
				%>
					<p></p>
				<%
					for (Customer cust : customers) {
						Long custkey = cust.getKey();
						String urldelete = "/deletecust.jsp?key=" + custkey.toString();
						String urledit = "/editcust.jsp?key=" + custkey.toString();
				%>
					<tr>
					<td><%=cust.getName()%> </td> <td> <%=cust.getAddress()%> </td>
					<td><%=cust.getCompany()%> </td><td><%=cust.getPhone()%></td>
					<td><a href='<%=urldelete%>'><img src="../img/hr.gif"
									width="16" height="16" alt="" /></a>&nbsp;</td>
				    <td><a href='<%=urledit%>'><img
									src="../img/edit-icon.gif" width="16" height="16" alt="" /></a></td>
					<p>	
					</tr>
 				<%
									}
					}
				%>
				</table>
				
				</div>
				
				</div> <!--end of center column div -->
				<div id="right-column">
				<strong class="h">INFO</strong>
				<div class="box">SimpleCRM, is an extremely simple and lightweight Customer Relationship Management Systems			
				<%
				UserService userService = UserServiceFactory.getUserService();
				User user = userService.getCurrentUser();
				if (user != null) {
				%>
				<p>Hello, <%=user.getNickname()%>! (You can
				<a href="<%=userService.createLogoutURL("/customers.jsp")%>">sign out</a>.)</p>
				<%
				} else {
				%>
				<p>Hello!
				<a href="<%=userService.createLoginURL(request.getRequestURI())%>">Sign in</a>
				to add customers</p>
				<%
				}
				%>		
				</div>
			</div>
		</div>
				
</body>
</html>